package com.bk.ouatadmin.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.bk.ouatadmin.service.UserService;
import com.mysql.jdbc.StringUtils;

@Controller
public class MainController {
	
	private static final Logger logger = LoggerFactory.getLogger(MainController.class);
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value="main.do") 
	public String main(Model model) {
		return "view/main";
	}

	@RequestMapping(value="loginpage.do")
	public String loginpage(Model model) {
		return "pure-view/loginpage";
	}
	
	@RequestMapping(value="logincheck.do")
	public String logincheck(@RequestParam Map<String,Object> paramMap, HttpSession session) {		
		if(StringUtils.isNullOrEmpty((String)paramMap.get("member_id"))){
			return "pure-view/loginpage";
		}else{
			HashMap<String, String> sessionMap = (HashMap<String, String>)userService.getAdminOne(paramMap);
			
			if(sessionMap !=null){
				session.setAttribute("login_session", sessionMap);
				return "redirect:/main.do";
			}else{
				return "pure-view/loginpage";
			}
		}
	}
	
}
